<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<%-- <base href="<%=basePath%>"> --%>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>门户基本页</title>
<script src="<%=basePath%>assets/js/jquery-1.10.1.min.js"></script>
<script src="<%=basePath%>assets/js/portal.js"></script>
<link href="../assets/css/reset.css" rel="stylesheet" />
<link href="<%=basePath%>${cssPath}" rel="stylesheet" />

<script type="text/javascript" >
function fixSize(){
/*		var w_h = window.innerHeight;
		var top_h = $('.hd_top').outerHeight();
		var logo_h = $('.header').outerHeight();
		var menu_h = $('#menuShow').outerHeight();
		var foot_h = $('.footer').outerHeight();
		var con_h = w_h - top_h - logo_h - menu_h - foot_h;
// 		con_h-=10;
		$('.ifra').css('height',con_h+'px');
//		console.log('con_h: '+con_h);
		if(con_h<400){
			$('.ui_wrap').addClass('unit_icon-wrap');
		}else{
			$('.ui_wrap').removeClass('unit_icon-wrap');
		}*/
		
		var con_h = document.body.scrollHeight;
    //	$('.ifra').css('height',con_h+'px');
		$('.ifra').css('height','550px');
		
		
//		$('.ifra').css('height','100%');
// 		console.log('win_h:'+w_h);
// 		console.log("ifr_h: "+$('.ifra').height());
}

	var  laycode ;	
	$(document).ready(function() {
	
		$("#theme").load('<%=basePath%>${templatePath}', function(){
			var portal_id=${portal_id};
			var userName = '${userName}';
			findLaycode(portal_id);
			$.ajax({
				type:"POST",
				url:"<%=basePath%>portal/previewPortal.do",
				data:{portal_id:portal_id},
				dataType:"text",
				global: false,
				success:function(data){					
					/* 显示日期 */
					var datetime =CurentTime();
	//				$(".header_right").append("<p><span>今天是"+datetime+"</span><span class='space'>|</span><a href='#'>设为首页</a></p>");		
					$(".header_right").append("<p><span>欢迎您："+userName+" </span><span> 今天是"+datetime+"</span><span class='space'>|</span><a href='#'>设为首页</a></p>");							

					var obj = eval ("(" + data + ")");
					var htmlstr = "";
					var str1 = "";
					var strblank="";
					var footercon = "${footerContent}";
					document.getElementById("tempLogo").src="<%=basePath%>${logoUrl}";
					
					if(laycode==1){
						var blankString="<div class='blank'></div>";
						$(".container").append(blankString);
						for(var i=0;i<obj.length;i++){						
							strblank="<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe id='ifr' class='ifra' src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%'></iframe></div>";
							 $(".blank").append(strblank);
						}
						//改变iframe高度
						fixSize();
						//动态改变iframe高度
						/*window.onresize = function(){
							fixSize();
						}*/
					}
					if(laycode==2){
					var leftString="<div class='left' ></div>";
					var rightString="<div class='right'></div>";									
					$(".container").append(leftString);
					$(".container").append(rightString); 													
					for(var i=0;i<obj.length;i++){								
						str1= "<div class='blank_left'><div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div></div>";
					 	htmlstr="<div class='blank_right'><div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div></div>";     
						if(obj[i].pagerow==1){	
							 $(".left").append(str1);						
						}
						else if(obj[i].pagerow==2){	 
							 $(".right").append(htmlstr);						
						}			
						}
					
					}
					
					if(laycode==3){
						var leftString="<div class='leftblank'></div>";
						var rightString="<div class='rightblank'></div>";
						var blankString="<div class='centerblank'></div>";
						$(".container").append(leftString);
						$(".container").append(rightString); 
						$(".container").append(blankString); 
						for(var i=0;i<obj.length;i++){
						str1= "<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div>";
					 	htmlstr="<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div>";  
					 	strblank="<div class='blank_hd'>"+obj[i].portletName+"</div><div class='blank_info'><iframe src="+obj[i].viewUrl+" frameborder='no' border='0' width='100%' height='265px'></iframe></div>";
						
						if(obj[i].pagerow==1){	
							 $(".leftblank").append(str1);						
						}
						else if(obj[i].pagerow==2){	 
							 $(".rightblank").append(htmlstr);						
						}	
						else if(obj[i].pagerow==3){	 
							 $(".centerblank").append(strblank);						
						}
							}
					}
					$(".footer").append(footercon);					
				 		menuList();
				 		showMenu(portal_id);
				},
					  	error:function(){
					    alert("页面加载失败，请重试");
				}					
			});	
		});										
	});
		
	//编辑内容的控制显示列数的js
	function findLaycode(portal_id){	 	
	$.ajax({
		type:"post",
		url:"/MSAPortal/portalAdmin/findByPortalid.do",
		data:{portal_id:portal_id},		
		async: false,
		success:function(datas){			
		var arr=eval ("("+datas+")");
	     var layid=arr.pagelayout;      
	     if(layid==1){
	    	 laycode=1;	
	     }else if(layid==2){
	    	 laycode=2;	    		   
	     }else{
	    	 laycode=3;
	     	}
	 	}
	}); 
	}
				
	//编辑内容的控制显示列数的js
	function showMenu(id){
	$.ajax({
		type:"post",
		url:"<%=basePath%>portal/showMenu.do",
		data:{portal_id:id},
		async: true,
		success:function(datas){

		if(datas== "" || datas == null){
			var strMenu = "<li class='menu_cur'><span class='menu_space'></span><a href='#' onclick='BReturn()'>工作台</a></li>";
			$('.menu').append(strMenu);
		}else{	
		var arr=eval ("("+datas+")");
    
		var strMenu = "<li class='menu_cur'><span class='menu_space'></span><a href='#' onclick='BReturn()'>工作台</a></li>";

		for(var i=0;i<arr.list.length;i++){
			strMenu+= "<li><span class='menu_space'></span> <a href='javascript:void(0);'>"+arr.list[i].one.businessType+"</a>";
			if(arr.list[i].twoList!=null){
				strMenu += "<div class='menu_sub' style='display:none;'>";

				for(var j=0;j<arr.list[i].twoList.length;j++) {
					
				 	strMenu += "<a href='javascript:void(0);'  onclick='openUrl(\""+arr.list[i].twoList[j].url+"\",\""+arr.list[i].twoList[j].systemHeight+"\",\""+arr.list[i].twoList[j].systemWidth+"\");menuSite(\""+arr.list[i].one.businessType+"\",\""+arr.list[i].twoList[j].appName+"\")'>"+arr.list[i].twoList[j].appName+"</a>";
			 	}
				strMenu += "</div>";
			}
		 strMenu += "</li>";  
		}		 
		
		 $('.menu').append(strMenu);
		 
		  $(".menu li").mousemove(function() {							

			  $(this).find('div').show();
				
			});
			$(".menu li").mouseleave(function() {				

				$(this).find('div').hide();
				
			}); 
		}	
	 }
	}); 
	}
	function menuSite(businessType,appName){
		$(".menu_site").empty();	
		$(".menu_site").append("协同管理平台","->"+appName); 
			
	}
	function menuList(){
		$(".menu_site").empty();	
		$(".menu_site").append("协同管理平台->工作台"); 
		
	}
	function BReturn(){
		parent.location.reload();   
	}
	function openUrl(url,systemHeight,systemWidth){
		
		$(".container").empty();	
// 		$('.container').append("<div><iframe src='"+url+"' frameborder='no' border='0' width='"+systemWidth+"' height='"+systemHeight+"'></iframe></div>");
		$('.container').append("<div><iframe class='ifra' src='"+url+"' frameborder='no' border='0' width='100%'></iframe></div>");
		//改变iframe高度
		fixSize();
		//动态改变iframe高度
		/*window.onresize = function(){
			fixSize();
		}*/
	}	
</script>

</head>
	   <div id="theme"></div>	   	
</html>
